package com.crm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.crm.domain.entity.Clue;
import com.crm.domain.query.ClueQuery;
import com.crm.mapper.ClueMapper;
import com.crm.service.ICluePoolService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class CluePoolServiceImpl extends ServiceImpl<ClueMapper, Clue> implements ICluePoolService {

    @Override
    public Page<Clue> queryPage(ClueQuery query) {
        // 1.构建条件
        // 1.1.分页条件
        Page<Clue> page = Page.of(query.getPageNum(),query.getPageSize());
        //2 分页查询条件
        LambdaQueryWrapper<Clue> wrapper = Wrappers.<Clue>lambdaQuery()
                .eq(query.getId() != null, Clue::getId, query.getId())
                .like(query.getPhone() != null, Clue::getPhone, query.getPhone())
                .eq(query.getChannel() != null, Clue::getChannel, query.getChannel())
                .between(query.getBeginCreateTime() != null, Clue::getCreateTime, query.getBeginCreateTime(), LocalDateTime.now());
        Page<Clue> cluePoolPage = page(page, wrapper);
        return cluePoolPage;
    }
}
